<template>
  <div class="role-page">
    <el-card class="role-card">
      <template #header>
        <div class="card-header">
          <span>角色管理</span>
          <el-button type="primary" @click="handleAdd">新增角色</el-button>
        </div>
      </template>
      
      <div class="content-wrapper">
        <el-table :data="roleList" style="width: 100%">
          <el-table-column prop="name" label="角色名称" />
          <el-table-column prop="code" label="角色编码" />
          <el-table-column prop="description" label="描述" />
          <el-table-column prop="createTime" label="创建时间" />
          <el-table-column label="操作" width="200">
            <template #default="scope">
              <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <div class="pagination-container">
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 30, 50]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="roleList.length"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

interface Role {
  id: number
  name: string
  code: string
  description: string
  createTime: string
}

const roleList = ref<Role[]>([
  {
    id: 1,
    name: '管理员',
    code: 'ADMIN',
    description: '系统管理员',
    createTime: '2024-03-14'
  },
  {
    id: 2,
    name: '普通用户',
    code: 'USER',
    description: '普通用户',
    createTime: '2024-03-14'
  }
])

// 分页相关
const currentPage = ref(1)
const pageSize = ref(10)

// 分页大小改变
const handleSizeChange = (val: number) => {
  pageSize.value = val
  currentPage.value = 1
}

// 当前页改变
const handleCurrentChange = (val: number) => {
  currentPage.value = val
}

const handleAdd = () => {
  console.log('新增角色')
}

const handleEdit = (row: Role) => {
  console.log('编辑角色', row)
}

const handleDelete = (row: Role) => {
  console.log('删除角色', row)
}
</script>

<style scoped>
.role-page {
  padding: 20px;
}

.role-card {
  min-height: 200px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.pagination-container {
  display: flex;
  justify-content: flex-end;
}

:deep(.el-card__body) {
  padding: 20px;
}
</style> 